﻿using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinformDevFramework.IServices;

namespace WinformDevFramework.Pages.Basic
{
    public partial class Form1 : Form
    {

        private int currentPage = 1;
        private int pageSize = 10;
        private int totalCount = 0;
        private List<w_Supplier> entities = new List<w_Supplier>();

        private Iw_SupplierServices _iwSupplierServices;
        public Form1(Iw_SupplierServices iwSupplierServices)
        {

            _iwSupplierServices = iwSupplierServices;
            InitializeComponent();
      
            dataGridView1.Scroll += dataGridView1_Scroll;
        }
        private List<w_Supplier> GetData(int CurrentPageRows, int PageSize, ref int totalCount)
        {
            List<w_Supplier> data = new List<w_Supplier>();
            data = _iwSupplierServices.Query(CurrentPageRows, PageSize, ref totalCount);
            return data;
        }

        private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
        {
            // 检查是否滚动到底部，需要加载更多数据

            LoadMoreEntities();

        }

        private void LoadMoreEntities()
        {
            // 加载更多实体数据
            var moreEntities = LoadEntities(currentPage, pageSize);
            if (moreEntities.Any())
            {
                entities.AddRange(moreEntities);
                currentPage++;
       
            }
        }



        private List<w_Supplier> LoadEntities(int startIndex, int pageSize)
        {
            // 模拟从数据源加载实体数据
            return GetData(startIndex, pageSize, ref totalCount);
        }



        private void LoadData(int startIndex, int count)
        {
            // 加载更多数据
            List<w_Supplier> newSupplierList = new List<w_Supplier>();
            newSupplierList = (GetData(startIndex, count, ref totalCount));

            // 累计数据
            entities.AddRange(newSupplierList);
            dataGridView1.DataSource = entities;
        }


        private void Form1_Load(object sender, EventArgs e)
        {

        }


    }
}
